package com.myidis.mapper;

import com.myidis.entity.AnalysisIndex;
import com.myidis.entity.AnalysisIndexBySubject;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.List;

public interface CIDIIndexManagementMapper {
    @Select("SELECT * FROM analysis_index_bysubject;")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "quota", column = "quota"),
            @Result(property = "subject", column = "subject"),
            @Result(property = "evaluate", column = "evaluate"),
            @Result(property = "uniformity", column = "uniformity"),
            @Result(property = "benchmark", column = "benchmark")
    })
    ArrayList<AnalysisIndexBySubject> bySubjectList();

    @Select("SELECT * FROM analysis_index_bycombination;")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "uniformity", column = "uniformity"),
            @Result(property = "evaluate", column = "evaluate"),
            @Result(property = "combination", column = "combination"),
            @Result(property = "benchmark", column = "benchmark"),
            @Result(property = "index", column = "index")
    })
    ArrayList<AnalysisIndex> byCombinationList();


    @Select("SELECT * FROM analysis_index_bycombination WHERE combination = #{combination} AND uniformity = #{uniformity};")
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "uniformity", column = "uniformity"),
            @Result(property = "evaluate", column = "evaluate"),
            @Result(property = "combination", column = "combination"),
            @Result(property = "benchmark", column = "benchmark"),
            @Result(property = "index", column = "index")
    })
    ArrayList<AnalysisIndex> getByUniformity(@Param("combination") String combination, @Param("uniformity") String uniformity);

    @Insert("INSERT intO analysis_index_bysubject(subject, quota, evaluate, uniformity, benchmark) " +
            "VALUES (#{subject}, #{quota}, #{evaluate}, #{uniformity}, #{benchmark});")
    int insertToSubject(AnalysisIndexBySubject add);

    @Insert("INSERT intO analysis_index_bycombination(index, uniformity, evaluate, combination, benchmark)"
            + " VALUES (#{index}, #{uniformity}, #{evaluate}, #{combination}, #{benchmark});")
    int insertToCombination(AnalysisIndex add);

    @Update("UPDATE analysis_index_bysubject SET  uniformity = #{uniformity}, "
            + "evaluate = #{evaluate} WHERE id = #{id} ;")
    int update(AnalysisIndexBySubject upd);

    @Delete("DELETE FROM `idis`.`analysis_index_bysubject` WHERE id = #{id} ")
    int deleteInSubject(int id);

    @Delete("DELETE FROM `idis`.`analysis_index_bycombination` WHERE id = #{id} ")
    int deleteInCombination(int id);
}
